package com.rgp.apipassenger.service.impl;

import com.rgp.apipassenger.feign.ServicePassengerUserClient;
import com.rgp.apipassenger.response.PassengerInfoResponse;
import com.rgp.apipassenger.service.PassengerUserService;
import com.rgp.internalcommon.dto.UserInfoDto;
import com.rgp.internalcommon.dto.ResponseResult;
import com.rgp.internalcommon.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-13 19:47
 */
@Service
public class PassengerUserServiceImpl implements PassengerUserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    @Override
    public PassengerInfoResponse getPassengerInfo(String accessToken) {

        //1.解析token，获取乘客的手机号
        UserInfoDto userInfoDto = null;
        try {
            userInfoDto = JwtUtils.paseToken(accessToken);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        //2.根据乘客的手机号，调用服务service-passenger-user，查询乘客的称谓 与 头像url
        ResponseResult<UserInfoDto> result = servicePassengerUserClient.getPassengerByPhoneNumber(userInfoDto.getUserPhone());
        //3.获取乘客头像url与称谓
        UserInfoDto data = result.getData();
        PassengerInfoResponse response = new PassengerInfoResponse();
        response.setPassengerName(data.getUserName());
        response.setProfilePhoto(data.getProfilePhoto());
        response.setPassengerPhone(userInfoDto.getUserPhone());

        return response;
    }
}